 var tableIns;
//友情链接JS文件
layui.use(['jquery','layer','table','form'],function(){
    var $ = layui.$,
        layer = layui.layer,
        form = layui.form,
        table = layui.table;
   
    tableIns = table.render({
		elem: '#blogrollTable', //指定原始表格元素选择器（推荐id选择器）
		cols: [
			[{
			field: 'id',
			align:'center',
			title: 'ID',
			sort: true,
		}, {
			field: 'title',
			align:'center',
			title: '标题',
			align: 'center',
		}, {
			field: 'url',
			align:'center',
			title: '链接',
			align: 'center',
		}, {
			field: 'picture',
			align:'center',
			title: '图片',
			align: 'center',
		}, {
			field: 'sort',
			align:'center',
			title: '排序',
			sort: true,
			align: 'center',
		}, {
			field: 'createTime',
			align:'center',
			title: '创建时间',
			templet: '#titleCreateTpl'
		}, {
			field: 'updataTime',
			align:'center',
			title: '修改时间',
			templet: '#titleUpdataTpl'
		}, {
			align:'center',
			title: '操作',
			toolbar: '#blogrollBar'
		}]
		], //设置表头
		url:'/systemsetup/basicsetup/blogroll/findPagingQuery',
		page: true,
		even: true,
		loading: true,
		limits: [10,30,60,90,150,300],
		limit: 10 //默认采用60
    });
    
    
    //监听工具条
    table.on('tool(blogrollTable)', function(obj){
    	var data = obj.data;
    	if(obj.event === 'detail'){
    		layer.open({
    			  type: 2,
    			  area: ['420px', '340px'], //宽高
    			  content: "/systemsetup/basicsetup/blogroll/showDetail?id="+data.id,
    			  end: function(){
    				tableIns.reload();
    			  }
      		});
    	} else if(obj.event === 'del'){
    		layer.confirm('真的删除行么', function(index){
    			delect(data.id);
    		});
    	} else if(obj.event === 'edit'){
    		layer.open({
  			  type: 2,
  			  area: ['420px', '340px'], //宽高
  			  content: "/systemsetup/basicsetup/blogroll/edit?id="+data.id,
  			  end: function(){
  				tableIns.reload();
  			  }
    		});
    	}
    });

    //有链接删除js
    function delect(id) {
		$.post("/systemsetup/basicsetup/blogroll/delectBlogroll",{"id":id},function(result){
			if (result.status == 200) {
				layer.msg(result.msg);
				tableIns.reload();
			} else {
				layer.msg(result.msg);
			}
		});
	}
    //监听提交
    form.on('submit(demo1)', function(data){
    	layer.close(layer.index);
      return false;
    });
    
    
   
    
    
});

function blogrollAdd() {
	layer.open({
		  type: 2,
		  area: ['420px', '340px'], //宽高
		  content: "/systemsetup/basicsetup/blogroll/addIndex",
		  end: function(){
			tableIns.reload();
		  }
		});
}